<template>
  <div class="el-container">
    <!-- 疾病列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="queryParams" inline label-width="80px">
        <el-form-item label="疾病名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入疾病名称"
            clearable
            size="small"
            @change="handleQuery"
          />
        </el-form-item>
      </el-form>
      <el-table :data="diseList" stripe border @row-click="selectDise">
        <el-table-column label="ICD编码" prop="icd"></el-table-column>
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column label="编码" prop="code"></el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div>
</template>
<script>
import { listDise } from "@/api/dms/dise";
export default {
  name: "Dise",
  props: ['selectedDiseList'],
  data() {
    return {
      // 设置隐藏列
      show: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      diseList: [],
      // 疾病目录名称
      name: null,
      // 弹出层标题
      title: "疾病列表",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        catId: null,
        code: null,
        name: null,
        icd: null,
        status: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询诊断类型(疾病)管理列表 */
    getList() {
      this.loading = true;
      listDise(this.queryParams).then(response => {
        this.diseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    addDise() {
      this.open = true;
      this.queryParams.pageNum = 1;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 选择一个疾病，添加到父组件疾病列表
    selectDise(row, column, event) {
        if(this.selectedDiseList.findIndex(v=>{return v.id===row.id}) !=-1) {
            this.$alert('已经存在该疾病，不能重复添加！', '提示')
            return;
        }
        // 传值给父组件
        this.$emit('diseListCallback', row)
        this.open = false
    }
  }
};
</script>